<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>隔行变色</title>
</head>
<body>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
    <li>隔行变色</li>
</body>
<script>
    window.onload = ()=>{
        let oLis = document.getElementsByTagName("li");
        
        for(i=0;i<oLis.length;i++){
            if(i%2==0){
                oLis[i].style.backgroundColor = 'red';
            }else{
                oLis[i].style.color = 'blue';
            }
        }
    }
</script>
</html>